/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Mcu_Soc.c                                                                                  *
 * \brief    AUTOSAR 4.3.1 MCAL Mcu Driver                                                              *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/03     <td>1.0U.0U                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Mcu_Soc.h"
#include "Mcu_GeneralTypes.h"
#include "Mcu_Fault.h"
#include "Mcal_Soc.h"

#define MCU_START_SEC_CODE_FAST
#include "Mcu_MemMap.h"
/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
/** *****************************************************************************************************
 * \brief To get cpu identify index .
 *
 * \verbatim
 * Syntax             : uint8 Mcu_GetCoreID(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : coreId
 *
 * Description        : To get cpu identify index .
 * \endverbatim
 *******************************************************************************************************/
/* PRQA S 1505 1 */
uint8 Mcu_GetCoreID(void)
{
    return Mcal_GetCpuIndex();
}

#define MCU_STOP_SEC_CODE_FAST
#include "Mcu_MemMap.h"

#define MCU_START_SEC_CODE
#include "Mcu_MemMap.h"

/** *****************************************************************************************************
 * \brief get the main frequency of each core.
 *
 * \verbatim
 * Syntax             : uint32 Mcu_Ip_SocGetCoreFreq(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : core main frequency, 0xFFFFFFFF means error.
 *
 * Description        : get the main frequency of each core.
 * \endverbatim
 *******************************************************************************************************/
uint32 Mcu_Ip_SocGetCoreFreq(void)
{
    Mcu_ClkRateType coreFreq = UINT32_MAX;
    uint8 CoreId = Mcu_GetCoreID();

    McuHook_Mcu_Ip_SocGetCoreFreq();
#if defined(CPU_cortex_r52)

    if (CoreId < (uint8)MCU_CPU_INDEX_MAX)
    {
        coreFreq = EXPECT_CORE_CLOCK_CR5_SE_R52;
    }

#endif
#if defined(CPU_cortex_r5)

    if (CoreId == MCU_CPU_INDEX_0)
    {
        coreFreq = EXPECT_CORE_CLOCK_CR5_LP;
    }

#endif
    return coreFreq;
}

/** *****************************************************************************************************
 * \brief mapped address convert to TCM physical address.
 *
 * \verbatim
 * Syntax             : uint32 soc_to_dma_address(uint32 cpuAddr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : mapped address
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : TCM physical address
 *
 * Description        : mapped address convert to TCM physical address.
 * \endverbatim
 *******************************************************************************************************/
uint32 soc_to_dma_address(uint32 cpuAddr)
{
    uint32 dmaAddr = Mcal_AddressConvert(cpuAddr);

    return dmaAddr;
}

#define MCU_STOP_SEC_CODE
#include "Mcu_MemMap.h"

#ifdef __cplusplus
}
#endif
/* End of file */
